package sk.naive.talker.command;

import sk.naive.talker.*;
import sk.naive.talker.message.*;

import java.rmi.RemoteException;

/**
 * Kidnap.
 *
 * @author <a href="mailto:maslenka@naive.deepblue.sk">Zuzana "Maslenka" Maslenova</a>
 * @version $Revision: 1.5 $ $Date: 2005/02/12 22:20:41 $
 */
public class Kidnap extends AbstractCommand {
	public void exec()
		throws CommandException,
		RemoteException
	{
		if (params == null || params.length() == 0) {
			sendMisusageWarning();
			return;
		}

		User victim = findTarget(params);
		if (victim == null) {
			return;
		}

		Location destLoc = new LocationHelper(commandDispatcher).locationForUser(user);
		Location originLoc = new LocationHelper(commandDispatcher).locationForUser(victim);

		ctxSet(user, DefaultMessageFactory.CTXKEY_VAL + "Vctm", victim.getProperties());
		if (destLoc == originLoc) {
			user.send(getString("kidnap.error", user.getProperties()));
			return;
		}
		MessageSendHelper msh = sendHelper();
		if (originLoc != null) {
			originLoc.userOut(victim);
			msh.sendLocal(user, originLoc, null, "kidnap.outphr", Category.MAGIC);
		}
		if (destLoc != null) {
			msh.sendLocal(user, "kidnap.ok", "kidnap.inphr", Category.MAGIC);
			destLoc.userIn(victim);
		}
		victim.send(getMessage("kidnap.victim", user.getProperties()));
		commandDispatcher.process("look", victim, null);
	}
}
